package leetcode.秋招.小马智行;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/8/28 16:36
 * @description：
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        int k = in.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            if (x > y) {
                list.add(-(x + y));
            } else {
                list.add(x + y);
            }
        }
        list.sort(Integer::compareTo);
        int[] nums = new int[list.size()];
        for (int i = 0; i < list.size() - 1; i++) {
            nums[i] = Math.abs(list.get(i) - list.get(i + 1));
        }
        nums[list.size() - 1] = 4 * N - Math.abs(list.get(0)) - Math.abs(list.get(list.size() - 1));
        System.out.println(Arrays.toString(nums));
        int sum = 0;
        k--;
        for (int i = 0; i < k; i++) {
            sum += nums[i];
        }
        int cur = sum;
        for (int i = k; i < nums.length * 2; i++) {
            cur = cur - nums[(i - k) % nums.length] + nums[i % nums.length];
            sum = Math.min(cur, sum);
        }
        System.out.println(sum);
    }
}
